<?php
class Banco {

	var $objConnection;
	var $arrFields = array();
	var $arrValues = array();

	function Banco($strBD_HOST_GLOBAL, $strBD_LOGIN_GLOBAL, $strBD_SENHA_GLOBAL, $strBD_CATALOGO_GLOBAL) {
		$this->objConnection = mysql_connect($strBD_HOST_GLOBAL, $strBD_LOGIN_GLOBAL, $strBD_SENHA_GLOBAL);
		mysql_select_db($strBD_CATALOGO_GLOBAL, $this->objConnection);
	}

	function Consultar($strQUERY) {
		$objRST = mysql_query($strQUERY, $this->objConnection);
		return $objRST;
	}

	function Executar($strQUERY) {
		$objRST = mysql_query($strQUERY, $this->objConnection);
		return $objRST;
	}

	function LimpaCampos() {
		$this->arrFields = array();
		$this->arrValues = array();
	}

	function CampoValor($strField, $strValue) {
		$this->arrFields[] = $strField;
		$this->arrValues[] = "'" . $strValue . "'";
	}

	function CampoValorNoStr($strField, $strValue) {
		$this->arrFields[] = $strField;
		$this->arrValues[] = $strValue;
	}

	function Inserir($strTable) {
		$strSQL = "INSERT INTO " . $strTable . " (";
		$strSeparator = "";
		for($i=0; $i < sizeof($this->arrFields); $i++) {
			$strSQL .= $strSeparator . $this->arrFields[$i];
			$strSeparator = ", ";
		}
		$strSQL .= ") VALUES (";
		$strSeparator = "";
		for($i=0; $i < sizeof($this->arrValues); $i++) {
			if ($this->arrValues[$i] == "@#DATA#@") {
				$strSQL .= $strSeparator . "getdate()";
			} else {
				$strSQL .= $strSeparator . $this->arrValues[$i];
			}
			$strSeparator = ", ";
		}
		$strSQL .= ");";
		return mysql_query($strSQL, $this->objConnection);
	}

	function GetInsertId() {
		return mysql_insert_id();
	}

	function Editar($strTable, $strPField, $strPValue) {
		$strSQL = "UPDATE " . $strTable . " SET ";
		$strSeparator = "";
		for($i=0; $i < sizeof($this->arrFields); $i++) {
			$strSQL .= $strSeparator . $this->arrFields[$i] . " = " . $this->arrValues[$i];
			$strSeparator = ", ";
		}
		$strSQL .= " WHERE " . $strPField . " = '" . $strPValue . "'";
		return mysql_query($strSQL, $this->objConnection);
	}
}
?>